package cn.oowoo.rabbitmq.transcation;

import cn.oowoo.rabbitmq.config.RabbitConfig;
import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
* @Author: Zhangbin
* @Date: 2021/5/9 12:26
* @Description:  事务消息测试 - 消费者
**/
public class TransactionConsumer {
    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = RabbitConfig.createConnection();
        // 创建消息通道
        Channel channel = connection.createChannel();

        channel.queueDeclare(RabbitConfig.QUEUE_TRANSACTION_NAME, false, false, false, null);

        DefaultConsumer consumer = new DefaultConsumer(channel) {
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                String msg = new String(body, "UTF-8");
                System.out.println("Received message : '" + msg + "'");
            }
        };
        channel.basicConsume(RabbitConfig.QUEUE_TRANSACTION_NAME, true, consumer);
    }
}
